#ifndef CMDENGINE_H
#define CMDENGINE_H

#include "Command.h"
#include "instanceholder.h"
#include <QObject>

class CmdEngine : public QObject
{
    Q_OBJECT
public:
    explicit CmdEngine(QObject* parent = 0);

    // TODO: create extended object creation (with library name)
    /**
     * \returns a newly created object id
     */
    QString createObject(const QString &clsname, const QVector<Command> &cmds);

    void singleCommand(const Command &cmd);

    QObject* thisObj() const;
    QObject* getObjById(const QString &id);

signals:
    void finished();

private slots:
    void finish();

private:
    void import(const Command &cmd);
    void assign(const Command &cmd);
    void rootobj(const Command &cmd);

    QScriptEngine mScriptEngine;
    InstanceHolder mHolder;
    QObject* mThisObj; // current object pointer
};

#endif // CMDENGINE_H
